<template>
  <CustomTableVue
    v-if="visible"
    :showLabel="false"
    :field-list="fieldList"
    :table-data="tableData"
    height="90%"
  >
  <template #action="slotProps">
     <div class="text-center" style="font-family:' DIN-Bold';color: rgba(0, 194, 255, 1);"  @click="jump(slotProps.row)">
      <img src="@/assets/image/svg/location2.png" class="icon" />
   </div>
   </template>
  </CustomTableVue>
</template>

<script lang="ts" setup>
import API from '@/network/api';
import axios, { Axios } from "axios"

import CustomTableVue from "@/components/common/table/CustomTable.vue";
import { useFunc } from '@/hook/useFunc';
const fieldList: any = [
  { name: "code", label: "编号", type: "TOOLTIP", width: 100},
  { name: "deviceType", label: "设备类型", type: "TOOLTIP", width: 120 },
  { name: "status", label: "状态", type: "TEXT" ,  width:90},
  { name: "type", label: "隐患类型", type: "TOOLTIP", width: 120 },
  { name: "time", label: "上报时间", type: "TOOLTIP"},
  { name: "action", label: "操作", type: "SLOT" ,  width: 80},
];

const visible = ref(false)
const tableData = ref([]);
const props = defineProps({
  selectValue: {
    type: String,
    default: ''
  },
});
const jsonData: any = inject("jsonData");
const current = computed(() => {
  let data = [];
  try {
    const obj = jsonData.value.yxjk.yhlb
    if(props.selectValue){
        data = obj[props.selectValue];

    }else{
        Object.values(obj).forEach((arr: any) => {
            data.push(...arr)
        })
    }
  } catch (error) {}

  return data;
});
const jump = (row: any) => {
  // console.log(row,'smndk');
  const apiUrl = import.meta.env.VITE_SERVER_URL;
          axios
            .get(apiUrl + '/build/getDeviceInfo', {
              params: {

                id: row.deviceID
              },
            })
            .then((res) => {
//  tableData.value=res.data.data
 console.log(res,'ndjsn');
        useFunc().flyByXY(res.data.data[0].x,res.data.data[0].y)
            })
            .catch((error) => {});
};
watch(
  () => current.value,
  (val) => {
    if (val) {
     tableData.value = val
     visible.value = false
     nextTick(() => {
      visible.value = true
     })
     
    }else{
        tableData.value = []
    }
  }
);
onMounted(() => {
  const apiUrl = import.meta.env.VITE_SERVER_URL;
          axios
            .get(apiUrl + '/build/getDeviceInfo', {
              params: {
                // type:null,
                // name:'',
                // id: ''
              },
            })
            .then((res) => {
//  tableData.value=res.data.data
//  console.log(tableData.value,'ndjsn');
        
            })
            .catch((error) => {});
//  let res =await API.common.getProjectInfo({
//   id: '',
//   name:'',
//  })
 
});
</script>
